package org.example.business.endpoint.http.server;

import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ChannelHandler extends ChannelInitializer {

    @Autowired
    private HttpMessageHandler httpMessageHandler;

    @Override
    protected void initChannel(Channel ch) throws Exception {

        ch.pipeline().addLast("request-decoder", new HttpRequestDecoder());
        ch.pipeline().addLast("req-decoder", new HttpMsgDecoder());

        ch.pipeline().addLast("response-encoder", new HttpResponseEncoder());
        ch.pipeline().addLast("rsp-encoder", new HttpMsgEncoder());

        ch.pipeline().addLast("message-handler", httpMessageHandler);

    }

}
